package com.qs.controller;


import com.qs.annotation.OperationLog;
import com.qs.pojo.dto.CommentDto;
import com.qs.pojo.dto.StoreCommentDto;
import com.qs.pojo.entity.StoreComment;
import com.qs.pojo.vo.OnlineVo;
import com.qs.pojo.vo.StoreCommentVo;
import com.qs.response.Response;
import com.qs.service.IStoreCommentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 店铺评价表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-12-17
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/store/comment")
@RequiredArgsConstructor
public class StoreCommentController {

    private final IStoreCommentService storeCommentService;

    /**
     * 前台获取店铺评价列表
     * @param storeId
     * @return
     */
    @GetMapping("/list/{storeId}")
    public Response listComments(@PathVariable("storeId") Integer storeId){
        log.info("获取店铺评价列表请求进来--------");
        List<CommentDto> commentDto = storeCommentService.listComments(storeId);
        return Response.success(commentDto);
    }

    /**
     * 后台获取店铺评价列表
     * @param pageNo
     * @param pageSize
     * @param storeCommentDto
     * @return
     */
    @GetMapping("/backend/list/{pageNO}/{pageSize}")
    public Response backendListComments(@PathVariable("pageNO") Integer pageNo,
                                        @PathVariable("pageSize") Integer pageSize,
                                        StoreCommentDto  storeCommentDto){
        log.info("获取店铺评价列表请求进来--------");
        Map<String,Object> map = storeCommentService.backendListComments(pageNo,pageSize,storeCommentDto);
        return Response.success(map);
    }

    /**
     * 删除店铺评论
     * @param id
     * @return
     */
    @GetMapping("/backend/remove/{id}")
    public Response deleteComments(@PathVariable("id") Integer id){
        log.info("删除店铺评论请求进来--------");
        storeCommentService.removeById(id);
        return Response.success();
    }

    /**
     * 店铺评价数据保存
     * @param storeComment
     * @return
     */
    @PostMapping("/save")
    public Response saveStoreComment(@RequestBody StoreComment storeComment){
        log.info("店铺评价数据保存");
        storeCommentService.save(storeComment);
        return Response.success();
    }
}
